package com.wy2.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.ScheduledFuture;

@Slf4j
@Component
@RestController
@RequestMapping("/dsq")
public class DingShiQi {
	@Autowired
    private ThreadPoolTaskScheduler threadPoolTaskScheduler;

	    private ScheduledFuture<?> future;
	    @Autowired
	    private ExecutePro executePro;

	    @Bean
	    public ThreadPoolTaskScheduler threadPoolTaskScheduler() {
	        return new ThreadPoolTaskScheduler();
	    }

	    @RequestMapping("/start")
	    public Integer start(){
	        try{
	            //每小时过一分执行策略 整点是采集数据的
	            future = threadPoolTaskScheduler.schedule(executePro,new CronTrigger("1 * * * * ?"));
	            return 1;
	        }catch (Exception e){
	            return 0;
	        }
	    }

	    @RequestMapping("/stop")
	    public Integer stop(){
	        try{
	            if (future != null) {
	                future.cancel(true);
	            }
	            return 1;
	        }catch (Exception e){
	            return 0;
	        }
	    }
	    
	}

/*
 * 
 * 
 * @Slf4j
 * 
 * @Component public class ExecutePro implements Runnable {
 * 
 * @Override public void run() { System.out.println("我在启动中"); ······ }
 * 
 * }
 */
	
